<?php

/**
 * Created by PhpStorm.
 * User: wukent
 * Date: 2017/9/20
 * Time: 上午10:31
 */
class MerchantModel extends Model
{

    public function getInfo($id) {
        $where = array('merchant_id'=>$id);
        $data = $this->where($where)->find();

        $seat = M("MerchantLocation")->where(array('merchant_id'=>$id))->field('coordinate')->find();

        $seatarr = explode(',',$seat['coordinate']);
        $data['longitude'] = $seatarr[0];
        $data['latitude'] = $seatarr[1];
        return $data;
    }


    	public function GetOne(){
		$merchant_id = I('get.merchant_id',29);
		$where       = array('merchant_id'=>$merchant_id);
		$data        = $this
		->where($where)
		->find();
		$link        = M('MerchantComment');
		$comment     = $link
		->join('LEFT JOIN ecs_users ON manage_merchant_comment.user_id = ecs_users.user_id ')
		->where($where)
		->limit(20)
		->select();
		$arr          = $this->each($comment);
		$data['comment'] = $arr;
		return $data;
	}

	public function each($arr){
		$link        = M('MerchantCommentPhoto');
		foreach($arr as $key =>$val){
			$data = $link
			->where("comment_id = {$val['comment_id']}")
			->select();
			$arr[$key]['photoList'] = $data;

		}
		return $arr;
	}



}